﻿<%@ WebService Language="C#"  Class="Muzei" %>

using System;
using System.Collections;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Web.UI.WebControls;

/// <summary>
/// Summary description for Muzei
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Muzei : System.Web.Services.WebService
{

    public Muzei()
    {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod(Description = " Ja vrakja cenata za vlez vo daden muzej")]

    public int VratiCena(int id_c)
    {


        string conString = ConfigurationManager.ConnectionStrings["konekcija"].ConnectionString;
        OleDbConnection conn = new OleDbConnection(conString);
        using (conn)
        {
            conn.Open();

            string sql = "SELECT Cena FROM Muzei WHERE ID_M=@id_c";
            OleDbCommand komanda = new OleDbCommand(sql, conn);
            komanda.Parameters.AddWithValue("@id_m", id_c);

            OleDbDataReader citac = komanda.ExecuteReader();
            citac.Read();
            return Convert.ToInt32(citac["Cena"].ToString());

        }
        return -1;
    }

    [WebMethod(Description = " Vrakja ime na muzej")]

    public string VratiImeMuzej(string id_c)
    {

        string greska = "";
        string conString = ConfigurationManager.ConnectionStrings["konekcija"].ConnectionString;
        OleDbConnection conn = new OleDbConnection(conString);
        using (conn)
        {
            conn.Open();

            string sql = "SELECT Muzej FROM Muzei WHERE ID_M=@id_c";
            OleDbCommand komanda = new OleDbCommand(sql, conn);
            komanda.Parameters.AddWithValue("@id_m", Convert.ToInt32(id_c));

            OleDbDataReader citac = komanda.ExecuteReader();
            citac.Read();
            return citac["Muzej"].ToString();

        }
        greska = "nema muzej";
        return greska;
    }
    [WebMethod(Description = "Ovoj metod se povikuva bez argumenti" +
        " vrakja dataset so site gradovi, muzei i nivna cena")]
    public DataSet VratiMuzei()
    {
        DataSet ds = IspolniMaster();
        return ds;

    }
    protected DataSet IspolniMaster()
    {
        string conString = ConfigurationManager.ConnectionStrings["konekcija"].ConnectionString;
        OleDbConnection conn = new OleDbConnection(conString);
        string sql = "SELECT  ID_M, Grad, Muzej, Cena FROM Muzei";
        OleDbCommand cmd = new OleDbCommand(sql, conn);
        OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
        DataSet ds = new DataSet();
        conn.Open();
        adapter.Fill(ds, "Muzei");
        conn.Close();
        return ds;
    }

    public class Muzej
    {
        public string id_m;
        public string grad;
        public string muzej;
        public string cena;
    }
    [WebMethod(Description = "ovoj metod se povikuva so argument od tipot Muzej i " +
        " vrakja true ako e uspesna promenata na muzejot koj se prosleduva kako argument")]
    public bool PromeniMuzej(Muzej m)
    {
        string conString = ConfigurationManager.ConnectionStrings["konekcija"].ConnectionString;
        OleDbConnection conn = new OleDbConnection(conString);
        string sql = "UPDATE Muzei SET Grad=@grad, Muzej=@muzej, Cena=@cena WHERE ID_M=@id_m";
        OleDbCommand komanda = new OleDbCommand(sql, conn);
        komanda.Parameters.AddWithValue("@grad", m.grad);
        komanda.Parameters.AddWithValue("@muzej", m.muzej);
        komanda.Parameters.AddWithValue("@cena", m.cena);
        komanda.Parameters.AddWithValue("@id_m", m.id_m);
        int status = 0;
        try
        {
            conn.Open();
            status = komanda.ExecuteNonQuery();
        }
        catch { }
        finally
        {
            conn.Close();

        }
        return (status == 1);
    }

    [WebMethod(Description = "ovoj metod se povikuva so argument od tipot Muzej i " +
        " vrakja true ako e uspesno dodavanje na muzej koj se prosleduva kako argument")]
    public bool DodajMuzej(Muzej m)
    {
        string conString = ConfigurationManager.ConnectionStrings["konekcija"].ConnectionString;
        OleDbConnection conn = new OleDbConnection(conString);
        string sql = "INSERT INTO Muzei ( ID_M, Grad, Muzej, Cena ) VALUES ( @id_m, @grad, @muzej, @cena ) ";
        OleDbCommand komanda = new OleDbCommand(sql, conn);
        komanda.Parameters.AddWithValue("@id_m", m.id_m);
        komanda.Parameters.AddWithValue("@grad", m.grad);
        komanda.Parameters.AddWithValue("@muzej", m.muzej);
        komanda.Parameters.AddWithValue("@cena", m.cena);
        
        int status = 0;
        try
        {
            conn.Open();
            status = komanda.ExecuteNonQuery();
        }
        catch { }
        finally
        {
            conn.Close();

        }
        return (status == 1);
    }

    [WebMethod(Description = "ovoj metod se povikuva so argument od tipot Muzej i " +
       " vrakja true ako e uspesno brisenje na muzej koj se prosleduva kako argument")]
    public bool BrisiMuzej(Muzej m)
    {
        string conString = ConfigurationManager.ConnectionStrings["konekcija"].ConnectionString;
        OleDbConnection conn = new OleDbConnection(conString);
        string sql = "DELETE FROM Muzei WHERE ID_M= @id_m ";
        OleDbCommand komanda = new OleDbCommand(sql, conn);
        komanda.Parameters.AddWithValue("@id_m", m.id_m);
        int status = 0;
        try
        {
            conn.Open();
            status = komanda.ExecuteNonQuery();
        }
        catch { }
        finally
        {
            conn.Close();

        }
        return (status == 1);
    }

}